import {
	baseUrl
} from './config.js'
const request = (options = {}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl,
			method: options.method || 'GET',
			data: options.data || {},
			header: options.header || {
				"Content-Type": "application/json",
				"X-Access-Token": uni.getStorageSync('token') ? uni.getStorageSync('token') : ''
			},
		}).then(res => {
			let {
				data
			} = res
			resolve(data);
		}).catch(error => {
			reject(error)
		})
	});

}


export const service = {
	get: (url, data, options = {}) => {
		options.method = 'GET'
		options.data = data
		options.url = url
		return request(options)
	},
	post: (url, data, options = {}) => {
		options.method = 'POST'
		options.data = data
		options.url = url
		return request(options)
	},
	put: (url, data, options = {}) => {
		options.method = 'PUT'
		options.data = data
		options.url = url
		return request(options)
	},
	delete: (url, data, options = {}) => {
		options.method = 'DELETE'
		options.data = data
		options.url = url
		return request(options)
	},
}